new Vue({
	el: '#app',
	data: {
		uid: '',
		api_token: '',
		user: '',
		path: '',
		nickname: '',
		email: '',
		name: '',
		sex: '',
		birthday: '',
		isCheckG: '',
		isCheckB: ''
	},
	mounted: function() {
		this.init();
	},
	methods: {
		init: function() {
			var self = this;
			self.uid = $api.getStorage('uid');
			self.api_token = $api.getStorage('api_token');
			//self.getMsg();
			apiready = function() {
				if(self.uid) {
					self.getMsg();
				} else {
					self.layout();
				};
			}
		},
		//登出
		layout: function() {
			api.openWin({
				name: 'login',
				url: '../../html/login/login.html',
				reload: true,
				vScrollBarEnabled: false,
				pageParam: {
					index: 4
				}
			});
		},
		//读取用户信息
		getMsg: function() {
			var self = this;
			console.log(self.uid);
			var data = {
				uid: self.uid,
				token: self.api_token,
			};
			$.post(base + config.user_show, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					self.user = msg.data;
					self.nickname = msg.data.nickname;
					self.name = msg.data.name;
					self.email = msg.data.email;
					self.birthday = msg.data.birthday;
					self.sex = msg.data.sex;
					self.checkSex(self.sex);
					self.path = msg.url;
				} else {
					console.log(msg.error_msg);
					api.toast({
						msg: msg.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		},
		//点击了那个性别
		issex: function(i) {
			var self = this;
			self.sex = i;
			if(i == "1") {
				self.isCheckB = true;
				self.isCheckG = false;
			} else {
				self.isCheckB = false;
				self.isCheckG = true;
			}
		},
		checkSex: function(i) {
			var el1 = $api.byId('btn');
			var el2 = $api.byId('btn2');
			console.log(i);
			if(i == "1") {
				$api.attr(el1, 'checked', 'checked');
				this.isCheckB = true;
				this.isCheckG = false;
			} else {
				$api.attr(el2, 'checked', 'checked');
				this.isCheckB = false;
				this.isCheckG = true;
			}
		},
		//修改个人信息
		editPersonMsg: function() {
			var self = this;
			console.log(self.uid);
			console.log(self.birthday);
			var data = {
				uid: self.uid,
				token: self.api_token,
				birthday: self.birthday,
				email: self.email,
				name: self.name,
				nickname: self.nickname,
				sex: self.sex
			};
			$.post(base + config.user_update, data, function(msg) {
				console.log(msg);
				if(msg.error == 0) {
					api.openWin({
						name: 'user-setting',
						url: 'userSetting.html',
						reload: true,
						vScrollBarEnabled: false,
						pageParam: {
							name: 'user-msg'
						}
					});
				} else {
					console.log(msg.error_msg);
					api.toast({
						msg: msg.error_msg,
						duration: 2000,
						location: 'middle'
					});
				}
			}, 'json');
		}
	}
})